-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IP address preference support for TCP connection #1015
Conversation
src/Microsoft.Data.SqlClient/netcore/src/Interop/SNINativeMethodWrapper.Windows.cs
Show resolved
Hide resolved
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPreference.xml
Outdated
Show resolved
Hide resolved
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPreference.xml
Outdated
Show resolved
Hide resolved
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPreference.xml
Outdated
Show resolved
Hide resolved
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPreference.xml
Outdated
Show resolved
Hide resolved
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionStringBuilder.xml
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs
Show resolved
Hide resolved
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPreference.xml
Show resolved
Hide resolved
I had a talk to someone with some networking experience and they pointed out that many applications will use addresses in the order returned from dns to connect to resources and so the first ip address in a list is likely to be the most connected route. This means that seemingly arbitrary choice of the last ip of each type may have been a deliberate attempt to choose the least used route. If this is true then that should have been called out in the code with a comment. I think trying each address returned in the order that they are returned will be more compatible with dns based load balancing schemes. When you look at parallelizing the connections you may want to keep track of the original ordering and when two connections succeed choose the first using the original ordering. |
Co-authored-by: David Engel <[email protected]>
…qlClient into IPAddressPreference
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs
Outdated
Show resolved
Hide resolved
…ent/SNI/SNITcpHandle.cs
# Conflicts: # src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj
This reverts commit 5642e74.
fd6c475
to
fb778fc
Compare
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Resources/Strings.Designer.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Javad <[email protected]> Co-authored-by: Cheena Malhotra <[email protected]>
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionString.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionString.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs
Outdated
Show resolved
Hide resolved
7939ea3
to
c41b411
Compare
+ improvement
c41b411
to
c71143c
Compare
Co-authored-by: Cheena Malhotra <[email protected]>
string sValue = (value as string); | ||
if (sValue is not null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be if (value is string sValue)
? the is
operator does the type and null checks so it's known to be a non-null string inside the if block if the condition returns true.
src/Microsoft.Data.SqlClient/netcore/src/Resources/Strings.Designer.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.Designer.cs
Outdated
Show resolved
Hide resolved
1615eac
to
12ff426
Compare
+ modify CancelAsyncConnections test
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPreference.xml
Show resolved
Hide resolved
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPreference.xml
Show resolved
Hide resolved
…eference.xml Co-authored-by: Cheena Malhotra <[email protected]>
+ Disable TNIR in connection string
5e5f4ce
to
019fce0
Compare
A new connection property
IPAddressPreference
is added to specify the IP preference by the client application when doing TCP connection. There are three valid types:IPv4First
This is the default preference. The driver will traverse IPv4 addresses first. If none of them can be connected successfully, it continues to try IPv6 addresses if there are any.
IPv6First
The driver will traverse IPv6 addresses first. If none of them can be connected successfully, it continues to try IPv4 addresses if there are any.
UsePlatformDefault
The driver will traverse all the IP addresses in their initial orders from DNS resolution.
To keep the consistency between managed SNI and native SNI, the connection logic is changed in
SNITcpHandle:Connect()
. Instead of keeping the last IPv4 and IPv6 addresses, all the valid IP addresses returned from DNS resolution will be tested in a row. There will be a separate PR containing this change in parallel.NOTE: This PR requires the change in native SNI so it requires a new version of Microsoft.Data.SqlClient.SNI to be released first.
cc @johnnypham @cheenamalhotra @David-Engel @saurabh500